package leetcode.biweekly.week94;

//Solution1Test
public class Solution1 {

	public int captureForts(int[] forts) {
		int ans = 0;
		for (int i = 0; i < forts.length; i++) {
			int num = forts[i];
			if (num == 1) {
				int p = i + 1;
				while (p < forts.length && forts[p] == 0) {
					p++;
				}
				if (p < forts.length && forts[p] == -1) {
					ans = Math.max(ans, p - i - 1);
				}
				i = p - 1;
			} else if (num == -1) {
				int p = i + 1;
				while (p < forts.length && forts[p] == 0) {
					p++;
				}
				if (p < forts.length && forts[p] == 1) {
					ans = Math.max(ans, p - i - 1);
				}
				i = p - 1;
			}
		}
		return ans;
	}
}
